{template 'header'}
<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">任务管理</a>
        <a>
          <cite>任务分类</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <div class="layui-row">
        <button class="layui-btn"
                onclick="x_admin_show('添加分类','{php echo $this->createWebUrl('task_cate',array('op'=>'add'))}')">
            <i class="layui-icon"></i>添加分类
        </button>
    </div>
    <xblock>
        <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
        <span class="x-right" style="line-height:40px">共有数据：{$total} 条</span>
    </xblock>
    <table class="layui-table layui-form x-admin">
        <thead>
        <tr>
            <th width="20">
                <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i
                        class="layui-icon">&#xe605;</i></div>
            </th>
            <th width="70">ID</th>
            <th>栏目名</th>
            <!--<th width="50">排序</th>-->
            <!--<th width="50">状态</th>-->
            <th width="250">操作</th>
        </thead>
        <tbody class="x-cate">
        {loop $list $item}
        <tr cate-id='{$item["id"]}' fid='{$item["pid"]}'>
            <td>
                <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='{$item["id"]}'><i
                        class="layui-icon">&#xe605;</i></div>
            </td>
            <td>{$item["id"]}</td>
            <td>
                {php echo str_repeat("&nbsp;&nbsp;&nbsp;&nbsp;",$item['lv']-1)}
                {if !empty($item['soncate'])}
                <i class="layui-icon x-show" status='true'>&#xe623;</i>
                {$item["name"]}
                {else}
                ├{$item["name"]}
                {/if}
            </td>
            <!--<td><input type="text" class="layui-input x-sort" name="order" value="{$item['sorts']}"></td>-->
            <!--<td>-->
                <!--<input type="checkbox" name="switch" lay-text="开|关" data-id="{$item['id']}" {if $item['isopen']}checked{/if} lay-skin="switch" value="1" lay-filter="switchDemo"/>-->
            <!--</td>-->
            <td class="td-manage">
                <button class="layui-btn layui-btn layui-btn-xs"
                        onclick="x_admin_show('编辑','{php echo $this->createWebUrl('task_cate',['op'=>'edit','id'=>$item['id']])}')">
                    <i class="layui-icon">&#xe642;</i>编辑
                </button>
                <button class="layui-btn layui-btn-warm layui-btn-xs"
                        onclick="x_admin_show('添加','{php echo $this->createWebUrl('task_cate',['op'=>'add','id'=>$item['id']])}')">
                    <i class="layui-icon">&#xe642;</i>添加子栏目
                </button>
                <button class="layui-btn-danger layui-btn layui-btn-xs" onclick="task_cate_del(this)"
                        data-id="{$item['id']}" href="javascript:;"><i class="layui-icon">&#xe640;</i>删除
                </button>
            </td>
        </tr>
        {/loop}
        </tbody>
    </table>
</div>
<script>
    layui.use(['form'], function(){
        var form = layui.form
            ,layer = layui.layer
        //监听指定开关
        form.on('switch(switchDemo)', function(data){
            var id = $(this).data('id')
            var yes = $(this).is(':checked') ? 1 : 0
            var url = '{php echo $this->createWebUrl("task_cate",array("op"=>"close"))}'
            $.post(url, {id,yes}, function (ret) {
                if (!ret.code) {
                    layer.msg(ret.msg, {icon: 0});
                }
            }, 'json')
        });
    });

    function task_cate_del(obj) {
        var id = $(obj).data('id')
        layer.confirm('确认要删除吗？', function (index) {
            //发异步删除数据
            var url = '{php echo $this->createWebUrl("task_cate",array("op"=>"del"))}'
            $.post(url, {id}, function (ret) {
                if (ret.code) {
                    layer.msg(ret.msg, {icon: 1,end:function () {
                            location.reload()
                        }});
                } else {
                    layer.msg(ret.msg, {icon: 0});
                }
            }, 'json')
        });
    }


    function delAll(argument) {
        var data = tableCheck.getData();

        layer.confirm('确认要删除吗？' + data, function (index) {
            //捉到所有被选中的，发异步进行删除
            var url = '{php echo $this->createWebUrl("task_cate",array("op"=>"del"))}'
            $.post(url, {'ids': data}, function (ret) {
                console.log(ret)
                if (ret.code) {
                    layer.msg(ret.msg, {icon: 1,end:function () {
                            location.reload()
                        }});
                } else {
                    layer.msg(ret.msg, {icon: 0});
                }
            }, 'json')
        });
    }
</script>
<script>var _hmt = _hmt || [];
(function () {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
})();</script>
</body>

</html>